C#

推荐列表 站点导航

当前位置:首页 > 脚本编程 > C# >

C#_c#字符串值类型与引用类型比较示例,复制代码 代码如下:classProgram{&

来源:网络整理  作者:  发布时间:2020-12-19 21:20
c#字符串值类型与引用类型比较示例,复制代码 代码如下:classProgram{ staticvoid Main() { int a = 9; //给变量a赋值为9 int b = a...

复制代码 代码如下:

        Console.WriteLine("After:m={0}", n.GetHashCode());
    staticint GetInt(int n)
using System;

{

        //此时获取到的哈希码值就是n的变量值
        int n = 99;
        int a = 9;    //给变量a赋值为9
        Person ZS = newPerson();       //张三
        Console.WriteLine(string.Format("a={0},b={1}", a, b));
    staticstring GetString(string s)
{
        //传过来的是地址而不"Hello",说明这时引用传递
        GetString(s);
证明string是引用类型

        SM.Age = 100;      //三毛年龄变成100,张三也就变成了100
classPerson

        string s = "Hello";
        Console.ReadKey();
    {
{

{
        Person SM = ZS;        //三毛等于张三,即张三和三毛就是同一个人


}
        Console.WriteLine("Before:n={0}", n.GetHashCode());
    {
        return n;

复制代码 代码如下:

classProgram

}


       Console.WriteLine(string.Format("A={0},B={1}", ZS.Age, SM.Age));
        Console.WriteLine("After:s={0}", s.GetHashCode());
    staticvoid Main()

}
    publicint Age { get; set; }
    }
    staticvoid Main()
        b = 10;
        Console.WriteLine("Before:s={0}", s.GetHashCode());
classProgram
        GetInt(n);


        return s;
    }

        int b = a;   //将a的副本给变量b
    }
        Console.ReadKey();

        ZS.Age = 99;           //张三的年龄是99
        //传过来的是变量值,说明这是值传递

相同的结构,不同的结果。

}
    {

相关热词: C#

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/c/5822.shtml

最新文章
热门文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

C#_c#字符串值类型与引用类型比较示例,复制代码 代码如下:classProgram{&

2020-12-19 编辑:

复制代码 代码如下:

        Console.WriteLine("After:m={0}", n.GetHashCode());
    staticint GetInt(int n)
using System;

{

        //此时获取到的哈希码值就是n的变量值
        int n = 99;
        int a = 9;    //给变量a赋值为9
        Person ZS = newPerson();       //张三
        Console.WriteLine(string.Format("a={0},b={1}", a, b));
    staticstring GetString(string s)
{
        //传过来的是地址而不"Hello",说明这时引用传递
        GetString(s);
证明string是引用类型

        SM.Age = 100;      //三毛年龄变成100,张三也就变成了100
classPerson

        string s = "Hello";
        Console.ReadKey();
    {
{

{
        Person SM = ZS;        //三毛等于张三,即张三和三毛就是同一个人


}
        Console.WriteLine("Before:n={0}", n.GetHashCode());
    {
        return n;

复制代码 代码如下:

classProgram

}


       Console.WriteLine(string.Format("A={0},B={1}", ZS.Age, SM.Age));
        Console.WriteLine("After:s={0}", s.GetHashCode());
    staticvoid Main()

}
    publicint Age { get; set; }
    }
    staticvoid Main()
        b = 10;
        Console.WriteLine("Before:s={0}", s.GetHashCode());
classProgram
        GetInt(n);


        return s;
    }

        int b = a;   //将a的副本给变量b
    }
        Console.ReadKey();

        ZS.Age = 99;           //张三的年龄是99
        //传过来的是变量值,说明这是值传递

相同的结构,不同的结果。

}
    {

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/c/5822.shtml

相关文章

风云图片

推荐阅读

返回C#频道首页